# 导包
from selenium import webdriver
from time import sleep

from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
# 获取浏览器驱动对象
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

service = Service('D:/ChromeDriver/chromedriver.exe')
driver =webdriver.Chrome(service=service)
driver.maximize_window()

# 打开注册A.html
driver.get("http://localhost/#/login")
# 使用css id 选择器 定位用户名 输入admin   - #userA

login_btn = (By.CSS_SELECTOR, "button.el-button")  # 改为更通用的选择器
username = driver.find_element(By.CSS_SELECTOR,"input[placeholder='账号']")
username.clear()

username.send_keys("admin")
# 使用css 属性选择 定位密码框 输入123456   - [name='passwordA']
password = driver.find_element(By.CSS_SELECTOR,"input[placeholder='密码']")
password.clear()
password.send_keys("123456")

login_btn_1 = driver.find_element(By.CSS_SELECTOR,"button.el-button")
login_btn_1.click()
sleep(2)

# # 获取登录后的信息
# print(driver.find_element(By.XPATH, "//div[@class='avatar-wrapper']//div//span").text)




# # 员工管理按钮
# emp_manager_btn = driver.find_element(By.XPATH,"//span[contains(text(),'员工管理')]")
# emp_manager_btn.click()
# sleep(2)
# # 查询员工
# emp = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入员工姓名']")
# emp.clear()
# emp.send_keys("冯海杰")
# sleep(1)
# print(driver.window_handles)
# # 点击查询按钮
# query_btn = driver.find_element(By.XPATH,"//span[contains(text(),'查询')]")
# query_btn.click()
# sleep(1)


# 添加员工

# # 点击添加员工按钮
# driver.find_element(By.XPATH,"//span[contains(text(),'添加员工')]").click()
# sleep(1)
# # 获取句柄
# print(driver.window_handles)
# # # 请输入账号
# user = driver.find_element(By.CSS_SELECTOR,"input[placeholder*='账号']")
# user.clear()
# user.send_keys("zgm")
# # 输入员工姓名
# driver.find_element(By.CSS_SELECTOR,"input[placeholder=''请输入员工姓名']").send_keys("朱名广")
# # 输入手机号
# driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入手机号']").send_keys("13526154268")
# # 输入身份证号
# driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入身份证号']").send_keys("120101190001010075")
# # 点击保存按钮
# driver.find_element(By.XPATH,"//span[contains(text(),'保存)]").click()

sleep(2)
# 点击菜品管理按钮
driver.find_element(By.XPATH,"//span[contains(text(),'菜品管理')]").click()
sleep(2)


# 输入菜品名称
dish_name = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请填写菜品名称']")
dish_name.clear()
dish_name.send_keys("广油手撕鸡")
sleep(1)
# 点击查询按钮
driver.find_element(By.XPATH,"//span[contains(text(),'查询')]").click()

# 添加菜品功能
sleep(1)
# 点击菜品添加按钮
driver.find_element(By.XPATH,"//span[contains(text(),'新建菜品')]").click()
# # 请输入菜品名称
sleep(2)
dish_add_name = driver.find_element(By.CSS_SELECTOR,"input[placeholder*='请填写菜品名称']")
dish_add_name.clear()
dish_add_name.send_keys("广油拉面")
sleep(2)
# 输入菜品价格
dish_price = driver.find_element(By.CSS_SELECTOR,"input[placeholder*='菜品价格']")
dish_price.clear()
dish_price.send_keys(10)
# 选择菜品分类
driver.find_element(By.CSS_SELECTOR,"input[placeholder*='菜品分类']").click()
# # 等待选项出现并点击
driver.find_element(By.XPATH,"//span[contains(text(),'广油')]").click()
sleep(2)
# 上传菜品图片
driver.find_element(By.CSS_SELECTOR, ".avatar-uploader-icon + input[type='file']").send_keys(r"C:\Users\13428154264\OneDrive\图片\2.jpg")
sleep(2)
# 输入菜品描述
sleep(1)
dish_description = driver.find_element(By.CSS_SELECTOR,".el-textarea__inner")
dish_description.clear()
dish_description.send_keys("广油的菜太棒了，快来吃")
# 点击保存
driver.find_element(By.CSS_SELECTOR, "button.el-button--primary.continue").click()
sleep(2)
# 输入菜品名称
dish_name = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请填写菜品名称']")
dish_name.clear()
dish_name.send_keys("广油拉面")
sleep(1)
# 点击查询按钮
driver.find_element(By.XPATH,"//span[contains(text(),'查询')]").click()
sleep(1)
# 删除菜品
driver.find_elements(By.XPATH,"//span[contains(text(),'删除')]")[1].click()
# 点击删除按钮
sleep(2)
driver.find_element(By.CSS_SELECTOR, "button.el-button.el-button--default.el-button--small.el-button--primary").click()

sleep(2)
driver.quit()